package cn.edu.scau.disk.utils;

import java.util.HashMap;
import java.util.Map;

public class R {

    private Integer code;

    private String message;

    public Map<String,Object> data;

    public R(){
        this(ErrorCode.SUCCESS);
    }

    public R(ErrorCode c){
        this.code = c.getCode();
        this.message = c.getMsg();
        this.data = new HashMap<>();
    }

    public static R ok(Map<String,Object> map){
        R r = new R();
        r.data.putAll(map);
        return r;
    }

    public static R ok(){
        return new R();
    }

    public static R fail(){
        return new R(ErrorCode.FAIL);
    }

    public static R fail(String msg){
        R r =R.fail();
        r.setMessage(msg);
        return r;
    }

    public R put(String key,Object value){
        this.data.put(key,value);
        return this;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }
}
